package pub.zhouhui;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import pub.zhouhui.ch1.aop.AopConfig;
import pub.zhouhui.ch1.aop.DemoAnnotationService;
import pub.zhouhui.ch1.aop.DemoMethodService;
import pub.zhouhui.ch1.di.DiConfig;
import pub.zhouhui.ch1.di.UseFunctionService;
import pub.zhouhui.ch1.javaconfig.JavaConfig;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
//        //依赖注入
//        // 使用AnnotationConfigApplicationContext 做为 Spring 容器。接受输入一个配置类作为参数。
//        AnnotationConfigApplicationContext contextDi = new AnnotationConfigApplicationContext(DiConfig.class);
//        // 获得声明配置的UseFunctionService 的Bean。
//        UseFunctionService useFunctionServiceDi = contextDi.getBean(UseFunctionService.class);
//        System.out.println(useFunctionServiceDi.SayHello("di"));
//        contextDi.close();
//
//        // java配置
//        AnnotationConfigApplicationContext contextJava = new AnnotationConfigApplicationContext(JavaConfig.class);
//        pub.zhouhui.ch1.javaconfig.UseFunctionService useFunctionServiceJava = contextJava.getBean( pub.zhouhui.ch1.javaconfig.UseFunctionService.class);
//        System.out.println(useFunctionServiceJava.SayHello("java 配置"));
//        contextJava.close();

        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AopConfig.class);
        DemoAnnotationService demoAnnotationService = context.getBean(DemoAnnotationService.class);
        DemoMethodService demoMethodService = context.getBean(DemoMethodService.class);
        demoAnnotationService.add();
        demoMethodService.add();
        context.close();
    }
}
